﻿using System;

namespace Borg.AttributeAnalyze.Result
{
    public class MissingParameterName : ResultBase
    {
        private readonly ParamDefinition _paramDef;
        private readonly ParamValue _paramValue;
        private readonly PlugTypeInfo _plug;
        private readonly SlotDefinition _slotDef;

        public MissingParameterName(PlugTypeInfo plug, ParamValue parameterValue)
            : base(plug.Assembly, Component.Plug, ResultType.MissingParameterName, plug, plug.ExtensionTypeInfo)
        {
            _plug = plug;
            _paramValue = parameterValue;
        }

        public MissingParameterName(SlotDefinition slotDefinition, ParamDefinition parameterDefinition)
            : base(slotDefinition.Assembly, Component.SlotDefinition, ResultType.MissingParameterName, slotDefinition, null)
        {
            _slotDef = slotDefinition;
            _paramDef = parameterDefinition;
        }

        public override string ToMsBuildMessageString()
        {
            if (Component == Component.SlotDefinition)
            {
                var str = _paramDef.HasDefaultValue
                    ? string.Format("parameter defaultvalue: {0}", _paramDef.DefaultValue)
                    : string.Format("no parameter defaultvalue", new object[0]);

                return string.Format(
                    "empty parameter name\n{0}slot name: {1}\n{0}interface: {2}\n{0}parameter type: {3}\n{0}{4}",
                    new object[] { GetWhiteSpace(2), Name, _slotDef.TypeName, _paramDef.Type.Name, str });
            }

            if (Component != Component.Plug)
                throw new NotImplementedException();

            return string.Format(
                "empty parameter name\n{0}slot name: {1}\n{0}class: {2}\n{0}parameter value: {3}",
                new[] { GetWhiteSpace(2), Name, TypeName, _paramValue.Value });
        }

        public override MessageType MessageType
        {
            get { return MessageType.Error; }
        }
    }
}

